using Microsoft.Extensions.Logging;
using Serilog;

namespace CoreManager.Core.Logging
{
    /// <summary>
    /// 日志格式示例
    /// 展示新的数据库日志格式效果
    /// </summary>
    public static class LogFormatExample
    {
        /// <summary>
        /// 展示新的SQL日志格式
        /// </summary>
        public static void ShowNewLogFormat()
        {
            // 模拟原来的日志格式（不美观）
            Console.WriteLine("=== 原来的日志格式（不美观）===");
            Console.WriteLine("info: 2025/9/11 13:53:22.174 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)");
            Console.WriteLine("      Executed DbCommand (2ms) [Parameters=[@__p_1='10', @__p_0='0'], CommandType='Text', CommandTimeout='30']");
            Console.WriteLine("      SELECT `s`.`Id`, `s`.`avatar`, `s`.`create_time`, `s`.`create_user_id`, `s`.`email`, `s`.`is_deleted`, `s`.`last_login_ip`, `s`.`last_login_time`, `s`.`password`, `s`.`phone`, `s`.`real_name`, `s`.`remark`, `s`.`status`, `s`.`update_time`, `s`.`update_user_id`, `s`.`user_name`");
            Console.WriteLine("      FROM `sys_user` AS `s`");
            Console.WriteLine("      WHERE NOT (`s`.`is_deleted`)");
            Console.WriteLine("      ORDER BY `s`.`create_time` DESC");
            Console.WriteLine("      LIMIT @__p_1 OFFSET @__p_0");
            Console.WriteLine();

            // 展示新的日志格式（美观）
            Console.WriteLine("=== 新的日志格式（美观易读）===");
            Log.Information(
                "🔍 [{CommandType}] {Duration}ms | {ConnectionId}\n" +
                "📝 SQL: {Sql}\n" +
                "📋 Parameters: {Parameters}",
                "QUERY",
                "2.00",
                "CoreManagerDbContext",
                @"SELECT `s`.`Id`, `s`.`avatar`, `s`.`create_time`, `s`.`create_user_id`, `s`.`email`, `s`.`is_deleted`, `s`.`last_login_ip`, `s`.`last_login_time`, `s`.`password`, `s`.`phone`, `s`.`real_name`, `s`.`remark`, `s`.`status`, `s`.`update_time`, `s`.`update_user_id`, `s`.`user_name`
  FROM `sys_user` AS `s`
  WHERE NOT (`s`.`is_deleted`)
  ORDER BY `s`.`create_time` DESC
  LIMIT @__p_1 OFFSET @__p_0",
                @"
    @__p_1 = 10 (Int32)
    @__p_0 = 0 (Int32)"
            );
        }
    }
}
